<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>登录页面</title>
    <link rel="stylesheet" href="./css/common.css"/>
    <link rel="stylesheet" href="./css/login.css"/>
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-3.1.1.min.js"></script>
    <script>
        // 通过 ajax 的⽅式实现登录过程
        $(function(){
            $("#submit").click(function(){
                var username = $("#username").val();
                var password = $("#password").val();

                if(username.trim() == "" || password.trim() == "") {
                    alert("用户名或者密码不能为空！");
                    return;
                }

                $.ajax({
                    url:"/login",
                    data:{"username":username,"password":password},
                    type:"POST",
                    dataType:"json",
                    success:function(data) {
                        console.log(data);
                        if(data.code == 1) {
                            alert("登录成功！");
                            //跳转到指定的页面了
                            window.location.href="client.html";
                        }else{
                            alert("登录失败，密码或者用户名错误！");
                            $("#user").val("");
                            $("#password").val("");
                        }
                    }
                });
            });
        });
    </script>
</head>
<!--导航栏-->
<body id="body">
<div class="nav">
    ⽹⻚聊天
</div>
<!--主窗口区-->
<div class="login-container">
    <div class="login-dialog">
        <!-- 标题 -->
        <h3>登录</h3>
        <!-- 输⼊⽤⼾名 -->
        <div class="row">
            <span>⽤户名</span>
            <input type="text" id="username" name="username">
        </div>
        <!-- 输⼊密码 -->
        <div class="row">
            <span>密码</span>
            <input type="password" id="password" name="password">
        </div>
        <!-- 提交按钮 -->
        <div class="row submit-row">
            <button id="submit">登录</button>
           <a href="register.html" id="register">注册</a>
        </div>
    </div>
</div>
</body>
</html>